<!-- src/views/message/NotificationMessage.vue -->
<template>
  <div class="notification-messages">
    <div
        v-for="notification in messages"
        :key="notification.activityId"
        class="notification-item"
        :class="{ unread: !notification.isRead }"
    >
      <div class="notification-header">
        <div class="notification-icon">
          <i class="fa fa-bullhorn"></i>
        </div>
        <div class="notification-title">{{ notification.title }}</div>
        <div v-if="!notification.isRead" class="unread-indicator"></div>
      </div>
      <div class="notification-content">
        <p>{{ notification.content }}</p>
        <div class="notification-time">{{ formatDate(notification.publishTime) }}</div>
      </div>
      <div class="message-actions">
        <button @click.stop="markRead(notification.activityId)" v-if="!notification.isRead">标记已读</button>
        <button @click.stop="deleteMessage(notification.activityId)">删除</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    messages: {
      type: Array,
      required: true
    }
  },
  methods: {
    markRead(activityId) {
      this.$emit('mark-read', activityId);
    },
    deleteMessage(activityId) {
      this.$emit('delete-message', activityId);
    },
    formatDate(dateStr) {
      if (!dateStr) return '';
      // 确保传入的是Date对象或时间戳
      const date = typeof dateStr === 'string' ? new Date(dateStr) : dateStr;

      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      return `${hours}:${minutes}`;
    }
  }
};
</script>

<style scoped>
.notification-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.notification-item {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: relative;
}

.notification-item.unread {
  border-left: 4px solid #F97316;
}

.notification-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.notification-icon {
  width: 40px;
  height: 40px;
  background: #E8F3FF;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  color: #165DFF;
}

.notification-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.notification-content {
  margin: 8px 0;
}

.notification-time {
  color: #999;
  font-size: 12px;
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.message-actions button {
  background: none;
  border: none;
  color: #165DFF;
  font-size: 12px;
  cursor: pointer;
}
.message-actions button:hover {
  text-decoration: underline;
}
</style>
